home *** CD-ROM | disk | FTP | other *** search
- //a_Matrix based objects
-
- #ifndef __RTTI__
- #error Must have RTTI enabled in order to use matrix derived classes
- #endif
-
- //////////////////////////////////////////////////////////////////////
- // AMatrixItem; based on ADataItem and AArray
- // a simulated 2D array with emphasis on easy resizing and blitting
- //////////////////////////////////////////////////////////////////////
- class AMatrixItem : RTTI_VIRTUAL public ADataItem, RTTI_VIRTUAL public AArray
- {
- public:
- //a_Declares debug/dump related functions
- #ifdef _DEBUG_DUMP_
- void dump(void); //a_Debugging dump, when _DEBUG_DUMP_ is set
- #endif
- };
-
- //////////////////////////////////////////////////////////////////////
- // AMatrix base class; based on AList (internally used) and ABaseElement for doOut
- //////////////////////////////////////////////////////////////////////
- class AMatrix : RTTI_VIRTUAL protected AList, RTTI_VIRTUAL public ABaseElement
- {
- public:
- AMatrix()
- {
- m_iX = m_iY = 0x0;
- }
- ~AMatrix() {};
-
- //a_Declares debug/dump related functions
- #ifdef _DEBUG_DUMP_
- void dump(void); //a_Debugging dump, when _DEBUG_DUMP_ is set
- #endif
-
- //ABaseElement overrides
- virtual void doOut(AStreamOutput *pasOut) const; //a_Standard output
-
- //a_Access operator
- AMatrixItem &operator[] (int iPY) { return _mGetAt(iPY); } //a_Access the row
- int mGetAt(int iPX, int iPY) const;
-
- //a_Redimension the array
- int mSetSize(int iSX, int iSY)
- {
- assert(iSX > 0 && iSY > 0 && iSX < INT_MAX && iSY < INT_MAX);
- if (iSX > 0 && iSY > 0)
- {
- return _mResize(iSX, iSY);
- }
- else
- assert(0x0);
-
- return 0x0; //a_Failed!
- }
-
- //a_Blit with an AArray type
- void mBlit(const AArray &aSource, int iPX = 0x0, int iPY = 0x0, int iSX = -0x1, int iSY = -0x1, int iMode = BLIT_COPY);
- void mBlit(const AMatrix &mSource, int iPX = 0x0, int iPY = 0x0, int iSX = -0x1, int iSY = -0x1, int iMode = BLIT_COPY);
-
- //a_Sets the matrix to the given state in a given mode at Pos and Size, default is a clear all
- void mSetPlane(int iState = 0x0, int iMode = BLIT_COPY, int iPX = 0x0, int iPY = 0x0, int iSX = -0x1, int iSY = -0x1);
-
- int mGetHeight(void) const { return m_iY; }
- int mGetWidth(void) const { return m_iX; }
- UINT mGetSize(void) const { return UINT(m_iX) * UINT(m_iY); }
-
- //a_Assigning an array out of a linear stream BYTE* (this changes the dimensions)
- void mSetFrom(BYTE *pbSource, int iArraySize, int iSX, int iSY); //a_Size is in BYTEs!
-
- protected:
- virtual int _mResize(int iSX, int iSY); //a_Allocation and resizing
- virtual int _mMapSizetoBYTEs(int iSize) { return iSize; } //a_1:1 in a BYTE matrix
- virtual int _mGetUnitsInBYTE(void) { return 0x1; } //a_A BYTE for BYTE... :) (trivial, but useful in case of further expansion of hierarchy)
-
- //a_Verify that the rectangle is within bounds
- void _mFixDimensions(int &iPX, int &iPY, int &iSX, int &iSY);
-
- AMatrixItem &_mGetAt(int iPY)
- {
- assert(m_padiHead);
- AMatrixItem *pmiY = CAST(AMatrixItem *, lGetAt(iPY));
- if (!pmiY) pmiY = CAST(AMatrixItem *, lGetLast());
- assert(pmiY);
- return *pmiY;
- }
-
- virtual void _mSetAt(int iPX, int iPY, int iState, int iMode = BLIT_COPY);
-
- int m_iX, m_iY; //a_X is the width, and Y is the height
- };
-
- //////////////////////////////////////////////////////////////////////
- // ABitMatrixItem; based on ADataItem and ABitArray
- //////////////////////////////////////////////////////////////////////
- class ABitMatrixItem : RTTI_VIRTUAL public ADataItem, RTTI_VIRTUAL public ABitArray
- {
- public:
- //a_Declares debug/dump related functions
- #ifdef _DEBUG_DUMP_
- void dump(void); //a_Debugging dump, when _DEBUG_DUMP_ is set
- #endif
- };
-
- //////////////////////////////////////////////////////////////////////
- // ABitMatrix container of ABitMatrixItem
- //////////////////////////////////////////////////////////////////////
- class ABitMatrix : public AMatrix
- {
- public:
- ABitMatrix() {};
- ~ABitMatrix() {};
-
- //a_Declares debug/dump related functions
- #ifdef _DEBUG_DUMP_
- void dump(void); //a_Debugging dump, when _DEBUG_DUMP_ is set
- #endif
-
- //a_Access overrides
- ABitMatrixItem &operator[] (int iPY) { return _mGetAt(iPY); } //a_Access the row
-
- //ABaseElement overrides
- virtual void doOut(AStreamOutput *pasOut) const { _doBitMatrix(pasOut); } //a_Standard output
- void bmDoXBitmap(AStreamOutput *pasOut) const { _doBitMatrix(pasOut, 0x1); } //a_image/x-xbitmap
-
- //a_Incestuous class dilemma: AMatrixItem and ABitMatrixItem
- //a_Given Z is a child of Y. M is a child of X and Y; N is a child of X and Z
- //a_Will both M and N have correct access from X and Y? Not unless you have RTTI
- //a_This is why I have mSetPlane defined here and not using the one in AMatrix
- void mSetPlane(int iState = 0x0, int iMode = BLIT_COPY, int iPX = 0x0, int iPY = 0x0, int iSX = -0x1, int iSY = -0x1);
-
- protected:
- //a_Output function
- void _doBitMatrix(AStreamOutput *pasOut, int iMirror = 0x0) const;
-
- //a_Getting of the items
- ABitMatrixItem &_mGetAt(int iPY)
- {
- assert(m_padiHead);
- ABitMatrixItem *pbmiY = CAST(ABitMatrixItem *, lGetAt(iPY));
- if (!pbmiY) pbmiY = CAST(ABitMatrixItem *, lGetLast());
- assert(pbmiY);
- return *pbmiY;
- }
-
- //a_Setting functions
- void _mSetAt(int iPX, int iPY, int iState, int iMode = BLIT_COPY);
-
- //a_Redimensioning
- virtual int _mResize(int iSX, int iSY); //a_Uses m_iX, m_iY to adjust the size
- virtual int _mMapSizetoBYTEs(int iSize) { return iSize / 0x8; } //a_8:1 in a bit matrix
- virtual int _mGetUnitsInBYTE(void) { return 0x8; } //a_8 bits in a BYTE (trivial, but useful in case of further expansion of hierarchy)
- };
-